Prolog's DCGs (definite clause grammars) seem to reduce options to a decision tree and only follow the first branch for the same options. x I just had to change the order of the clauses.